<?php
   $auth = Auth::getAuth('current_user');
   $userCompany = new userQueries();
   $company = $userCompany->getCompany($auth['company_id']);
?>
<link rel="stylesheet" href="/css/jquery-ui.css" />
<script type="text/javascript" src="/js/functions/workflow.js"></script>
<div class="fl-create-workflow-wrapper">
	<?php  include 'layout/workspace_header.php' ?>
	<div class="contentBar_workspace" style="margin-top:34px;">
	    <div class="fl-workspace-wrapper">
			<!-- <div class="fl-option-toolbar">
				<div class="fl-toolbar-left-wrapper">
					<i class="fa fa-retweet"></i> <span>Workflow Chart</span>
				</div>
				<div class="fl-toolbar-right-wrapper">
					<ul class="fl-breadcrums">
						<li><a href="/home"><div class="home icon"></div> <i class="fa fa-caret-right"></i></a></li> 
						<li><a href="/user_view/organizational_chart">Organizational Chart <i class="fa fa-caret-right"></i></a></li> 
						<li><a href="/user_view/formbuilder">Form Builder <i class="fa fa-caret-right"></i></a></li> 
						<li><a href="/user_view/workflow">Workflow</a></li>
					</ul>
				</div>
			</div> -->
			<div class="fl-workspace">
				 <div style="display:table;">
	         <div style="display:table-row">
	            <div style="display:table-cell"></div>
	            <div class="topPointerRuler-container" style="position:relative; display:table-cell;width: auto;height: 100%;border: 1px solid #ddd;border-bottom: none;">
	                  <div class="topPointerRuler-tip" style="width: 10px;background-color: #000;height: 10px;cursor: pointer;"></div>
	            </div>
	         </div>
	         <div style="display:table-row">
	            <div  class="leftPointerRuler-container" style="position:relative;display:table-cell;white-space:nowrap;vertical-align:top;width: 10px;height: 600px;border: 1px solid #ddd;">
	                  <div class="leftPointerRuler-tip" style="width: 10px;background-color: #000;height: 10px;cursor: pointer;"></div>
	            </div>
	            <div style="display:table-cell">
	              <div class="workspace workflow_ws" style="position:relative">
	                  <!-- Node -->
	               </div>
	            </div>
	         </div>
		 <?php
      $db = new Database();
      $workflow_id = $_GET['id'];
      $form_id = $_GET['form_id'];
      if (isset($_GET['id'])) {
         //Get orgchart information and nodes query
         $workflow_nodes_array = $db->query("SELECT * FROM tbworkflow tbw LEFT JOIN tbworkflow_objects tbwo
                                     on tbw.id = tbwo.workflow_id 
                                     WHERE tbw.id = '". $workflow_id ."'","array");
         if(count($workflow_nodes_array)==0){
            header("location:/");
         }
      
         $ws_size = json_decode($workflow_nodes_array[0]['tbw_json'],true);
         $ws_height = $ws_size['height'];
         $ws_width = $ws_size['width'];

          //node array
          $nodes_json = array();
          //extract nodes and add to array
          foreach($workflow_nodes_array as $workflow_nodes){
             array_push($nodes_json,$workflow_nodes['json']);
          }
          //convert array to json array
          $nodes_json =  json_encode($nodes_json);
          
          //Get orgchart lines query
          $workflow_lines_array = $db->query("SELECT * FROM tbworkflow_lines 
                                      WHERE workflow_id = '". $workflow_id ."'","array");
          //lines array
          $lines_json = array();
          //extract lines and add to array
          foreach($workflow_lines_array as $workflow_lines){
             array_push($lines_json,$workflow_lines['json']);
          }
          $lines_json = json_encode($lines_json);
      }
      ?>
      
      <div id="workflow_nodes" class="display"><?php echo $nodes_json; ?></div>
      <div id="workflow_lines" class="display"><?php echo $lines_json; ?></div>
      <div id="workflow_height" class="display"><?php echo $ws_height; ?></div>
      <div id="workflow_width" class="display"><?php echo $ws_width; ?></div>
      <input id="form_id" class="display" type="text" value="<?php echo $form_id ?>" />
      <input class="display userLevel" type="text" value="<?php echo $auth['user_level_id'] ?>" />
		 
		 
		 
	      </div><!-- /end of display table -->
			</div><!-- /end of fl-workspace -->
			<?php
$search = new Search();

//get departments
$getAllDepartment = $search->getAllDepartment();
echo "<div class='departments display'>" . json_encode($getAllDepartment) . "</div>";

//get positions
$getPosition = $search->getAllPosition();
echo "<div class='positions display'>" . json_encode($getPosition) . "</div>";

//get users
$getUsers = $search->getAllUsers();
echo "<div class='users display'>" . json_encode($getUsers) . "</div>";

$getForms = $db->query("SELECT id,form_name FROM tb_workspace WHERE company_id={$db->escape($auth['company_id'])} AND is_active =1","array");
$getForm_properties = $db->query("SELECT * FROM tb_workspace WHERE id={$db->escape($form_id)}", "row");


$active_fields = functions::getFormFields($form_id);
$form_columns = array();
foreach ($active_fields as $value) {
    array_push($form_columns, $value);
}

//form properties and others
echo '<input type="text" class="class form_buttons display" value="' . $getForm_properties['form_buttons'] . '">';
echo '<input type="text" class="class form_fields display" value=' . json_encode($form_columns) . ' />';
echo '<div class="company_forms display">' . htmlspecialchars(json_encode($getForms)) . ' </div>';
?>	
			<?php include 'layout/form_controls.php' ?>
			<!-- <div class="fl-form-properties-wrapper">
				<div class="fl-widget-head">
					<span class="widget-title"><i class="fa fa-cogs"></i> properties</span>
					<div class="fl-form-properties-toggle">
						<i class="fa fa-chevron-right"></i>
					</div>
				</div>
				<div class="fl-props-container">
					<div class="fl-form-setting-wrapper">
						<div class="fl-widget-head">
							<span class="widget-title">Form Settings</span>
							<span class="fl-min-max-properties" fl-show-opt="true"><i class="fa fa-plus"></i></span>
						</div>
						<div class="fl-form-setting-content fl-for-scroll">
							<label>Custom Form Size</label>
							<div class="fl-option-form-wrapper">
								<input type="text" style="float:left;" placeholder="Width" value="1030">
								<input type="text" style=" float:right;" placeholder="Width" value="600">
								<div class="clearfix"></div>
							</div>
							<div class="fl-option-form-wrapper">
								<label>Form Size</label>
								<select class="form-select form_size">
		                            <option value="8.5x11">Letter(8.5in x 11in)</option> 
		                            <option value="8.5x14">Legal(8.5in x 14in)</option> 
		                            <option value="7.25x10.5">Executive(7.25in x 10.5in)</option> 
		                            <option value="8.27x11.69">A4(8.27in x 11.69in)</option> 
		                            <option value="33.11x46.61">A0(33.11in x 46.61in)</option> 
		                            <option value="23.39x33.11">A1(23.39in x 33.11in)</option> 
		                            <option value="16.53x23.39">A2(16.53in x 23.39in)</option> 
		                            <option value="11.69x16.53">A3(11.69in x 16.53in)</option> 
		                            <option value="8.27x11.69">A4(8.27in x 11.69in)</option> 
		                        </select>	
							</div>
							<div class="fl-option-form-wrapper">
								<label>Show Ruler</label><Br/>
								<label>Yes: <input type="radio" value="yes" class="f-show-ruler" name="show-form-ruler-select"></label>
								<label>No: <input type="radio" value="no" checked="checked" class="f-show-ruler" name="show-form-ruler-select"></label>
								
							</div>
						</div>
					</div>
					<div class="fl-form-actions-wrapper">
						<div class="fl-widget-head">
							<span class="widget-title">Form Actions</span>
							<span class="fl-min-max-properties" fl-show-opt="true"><i class="fa fa-plus"></i></span>
						</div>
						<div class="fl-form-actions-content fl-for-scroll">
							 <button class="btn-basicBtn padding_5 cursor save_workspace tip fl-command-btn" data-original-title="Save Workflow" data-workspace="Workflow Chart" data-form-type="workflow"><i class="fa fa-floppy-o"></i> Save</button>
							<button class="btn-basicBtn padding_5 cursor clear_all_nodes fl-command-btn tip" data-original-title="Clear Workspace"><i class="fa fa-times"></i> Clear All</button>
							<button class="btn-basicBtn padding_5 cursor preview_form tip fl-command-btn" data-original-title="Preview Workflow" data-form-type="workflow"><i class="fa fa-search"></i> Preview</button>
							<a href="/user_view/formbuilder?formID=<?php echo $_GET['form_id']; ?>&view_type=edit" class="tip cursor" data-original-title="Related Form" data-placement="top" id="" data-form-id="1" style=""><button class="btn-basicBtn fl-command-btn padding_5 cursor"><i class="fa fa-list-alt"></i> Form</button></a>
		
						</div>
					</div>
					<div class="fl-form-controls-wrapper">
						<div class="fl-widget-head">
							<span class="widget-title">Form Controls</span>
							<span class="fl-min-max-properties" fl-show-opt="true"><i class="fa fa-plus"></i></span>
						</div>
						<div class="fl-form-controls-content fl-for-scroll">
							<button class="btn-basicBtn padding_5 cursor start_node tip fl-command-btn" data-original-title="Add Start Node" data-object-type="startNode" data-drop="workspace"><i class="fa fa-play-circle-o"></i> Start Node</button>
	                         <button class="btn-basicBtn padding_5 cursor end_node tip fl-command-btn" data-original-title="Add End Node" data-object-type="endNode" data-drop="workspace"><i class="fa fa-stop"></i> End Node</button>
	                        <button class="btn-basicBtn padding_5 cursor process_node tip fl-command-btn" data-original-title="Add Process Node" data-object-type="processNode" data-drop="workspace"><i class="fa fa-user"></i> Process Node</button>

							<button class="btn-basicBtn padding_5 cursor  conditional_node tip fl-command-btn" data-original-title="Add Conditional Node" data-object-type="conditionalNode" data-drop="workspace"><i class="fa fa-question-circle"></i> Conditional</button>
	            
	            
	                    </div>
					</div>
				</div>
			</div> --><!-- /end of fl-form-properties -->
			<div class="clearfix"></div>
		</div>
	</div>	
</div>
